﻿using System;
using System.Collections;
using System.Globalization;
using System.Linq;
using System.Windows;
using System.Windows.Data;

namespace be.metanous.mvvm.converters
{
    public class InverseEnumToHiddenVisibilityConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (parameter.GetType().IsArray)
            {
                if (value != null)
                {
                    if (((IEnumerable)parameter).Cast<object>().Contains(value))
                    {
                        return Visibility.Hidden;
                    }
                }
            }
            else
            {
                if (DependencyProperty.UnsetValue.Equals(value))
                {
                    return Visibility.Visible;
                }

                if (value != null)
                {
                    if (value.Equals(parameter))
                    {
                        return Visibility.Hidden;
                    }
                }
            }

            return Visibility.Visible;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
